For SVG icons, prefer Icon.paintIcon over Graphics.drawImage#8309
Merged
eirikbakke merged 1 commit intoapache:masterfrom Mar 12, 2025
Merged
For SVG icons, prefer Icon.paintIcon over Graphics.drawImage#8309eirikbakke merged 1 commit intoapache:masterfrom
eirikbakke merged 1 commit intoapache:masterfrom
Conversation
691107c to
2f150ee
Compare
…resolution. Various SVG icons were previously shown in a lower resolution due to being painted with Graphics.drawImage(ImageIcon, x, y, null) instead of Icon.paintIcon(null, Graphics, x, y). This PR changes the former to the latter in all the simple cases that were found throughout the codebase (by grepping for 'drawImage' and manually reviewing each case). For example, the lightbulb icons in the editor gutter, and the actions in the menu that shows up when you click them, were shown in low resolution on Windows 11 with 150% HiDPI scaling enabled. This is mostly an improvement for screens with a fractional HiDPI scaling (e.g. 150%) on Windows. On 200% scaling (including on MacOS), icons are drawn properly even with drawImage, due to ImageUtilities returning MultiResolutionImage instances nowadays with 1x and 2x resolutions present.
Contributor
Author
|
Thanks for the quick review! Will merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here are a few more changes to ensure that SVG icons render at full resolution on HiDPI screens.
This PR handles the transformation from
Graphics.drawImage(ImageIcon, x, y, null)to
Icon.paintIcon(null, Graphics, x, y)at various places in the codebase.
This fixes e.g. poor-resolution lightbulb icons in the editor gutter on Windows at fractional HiDPI scale factors. See the before/after screenshot below, which was taken on Windows 11 with the 150% HiDPI scaling level.
All simple such cases were found by grepping for "drawImage" and reviewing each case. Test classes and NBI related classes were skipped.
This is mostly an improvement for screens with a fractional HiDPI scaling (e.g. 150%) on Windows. On 200% scaling (including on MacOS), icons are drawn properly even with drawImage, due to ImageUtilities returning MultiResolutionImage instances nowadays with 1x and 2x resolutions present. The latter is still a good fallback for cases that may not yet be covered otherwise.